#ifndef _SERVICECONN_HXX_
#define _SERVICECONN_HXX_

#include "mytypes.h"
#include "mythread.hxx"
#include "bridgemessage.hxx"
#include "safeque.hxx"

class TcpSocket;
class BridgeDB;
class FileLog;
class BridgeNet;
class AtkConnManager;

class AtkConn : public Thread
{
public:
  //
  AtkConn(AtkConnManager* manager, TcpSocket *remote, FileLog *filelog);
  virtual ~AtkConn();

  void Shutdown();
  
  //Will be called by mobile phone manager
  void SendMsg(tBridgeMsg* bmsg);
  
  virtual const string &PeerHostAddress() const;
  virtual unsigned short PeerHostPort() const;

private:
 // 
  AtkConn(const AtkConn &model);
  
  virtual void Execute(Arg arg);

  bool HandleIn();
  bool HandleOut();
  
  bool HandleMsg(tBridgeMsg* bmsg);
  
  AtkConnManager* _manager;
  
  tBridgeMsgQue _bmsg_que;
  TcpSocket* _remote;
  BridgeNet* _bridgenet;

  bool _shutdown_requested;
  FileLog *_filelog;
};

#endif //_SERVICECONN_HXX_
